package com.vf.admin.client.dao;

import com.vf.admin.common.db.BaseDao;
import com.vf.admin.common.splitpage.SplitPageBean;
import com.vf.admin.miaodong.entity.SsCities;
import com.vf.admin.utils.StringEx;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 市
 */
@Repository
public class AppSsCitiesDao extends BaseDao<SsCities>{

    /**
     * 查询列表
     */
    public List<SsCities> list() {
        ArrayList<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder(" select * from ss_cities where 1=1  ");
        sbStr.append(" ORDER BY id ASC ");
        String sql = sbStr.toString();
        return this.queryList(sql,paramList, SsCities.class,null);
    }

    /**
     * 详情
     */
    public SsCities get(Integer id) {
        if (StringEx.isNullOrLing(id)) {
            return null;
        }
        List<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder(" select * from ss_cities where 1=1");
        sbStr.append(" and id = ? ");
        paramList.add(id);
        String sql = sbStr.toString();
        return this.queryObj(sql, paramList, SsCities.class);
    }


    /**
     * 添加/修改
     */
    public void save(SsCities haoYou) {
        if (haoYou.getId() != null && haoYou.getId() > 0) {
            this.update(haoYou);
        } else {
            haoYou.setId(this.add(haoYou));
        }
    }

    /**
     * 删除
     */
    public void del(Integer id) {
        if (id <= 0) {
            return;
        }
        String sql = " delete  from ss_cities where id = ?";
        ArrayList<Object> paramList = new ArrayList<Object>();
        paramList.add(id);
        this.del(sql, paramList);
    }

    /**
    * 根据省编码查询对应市
    * @Param: [provinceid]
    * @return: java.util.List<com.vf.admin.miaodong.entity.SsCities>
    * @Author: zhouyunyi
    * @Date: 2021/07/21
    * @Time: 17:57
    */
    public List<SsCities> findByCitie(Integer provinceid){
        ArrayList<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder("select * from ss_cities where 1=1  ");
        if(StringEx.isNotNull(provinceid)){
            sbStr.append(" and provinceid = ? ");
            paramList.add(provinceid);
        }
        sbStr.append(" ORDER BY id ASC ");
        String sql = sbStr.toString();
        return this.queryList(sql,paramList, SsCities.class);
    }

    /**
    * 根据城市编码获取城市
    * @Param: [cityid 城市编码]
    * @return: com.vf.admin.miaodong.entity.SsCities
    * @Author: zhouyunyi
    * @Date: 2021/07/21
    * @Time: 18:45
    */
    public SsCities getCitie(Integer cityid){
        if (StringEx.isNullOrLing(cityid)) {
            return null;
        }
        List<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder(" select * from ss_cities where 1=1");
        sbStr.append(" and cityid = ? ");
        paramList.add(cityid);
        String sql = sbStr.toString();
        return this.queryObj(sql, paramList, SsCities.class);
    }

}
